public class Canvas {
    private int row, col;
    private char data[][];
    private char borderCh;

    public Canvas() {
        row = 10;
        col = 60;
        data = new char[row][col];
        borderCh = '#';
    }

    public Canvas(int row, int col, char ch) {
        this.row = row;
        this.col = col;
        this.data = new char[row][col];
        this.borderCh = ch;
    }

    public Canvas init() {
        int i, j;

        for (i = 0; i < row; ++i) {
            for (j = 0; j < col; ++j) {
                if (j == 0 || i == 0 || i == row - 1 || j == col - 1)
                    data[i][j] = borderCh;
                else
                    data[i][j] = ' ';
            }
        }

        return this;
    }


    public int w() {
        return col;
    }

    public int h() {
        return row;
    }

    public boolean check(int r, int c) {
        if (r == 0 || c == 0 || r == row - 1 || c == col - 1)
            return false;
        return true;
    }

    public boolean check(Pos pos) {
        return check(pos.x, pos.y);
    }

    public Canvas set(int r, int c, char ch) {
        data[r][c] = ch;
        return this;
    }

    public Canvas set(Pos pos, char ch) {
        return set(pos.x, pos.y, ch);
    }

    public Canvas set(SnakePixel pixel) {
        return set(pixel.x, pixel.y, pixel.ch);
    }

    public char get(int r, int c) {
        return data[r][c];
    }
}
